﻿using ViewMaker.Core.Controls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using ViewMaker.Core;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Data;

namespace ViewMaker.Core.Tests
{
    [TestClass()]
    public class LabelViewControlTest
    {
        [TestMethod()]
        public void 標準的なLabelのXAML生成()
        {
            var target = new LabelViewControl { Item = new ViewLayoutItem { Name = "lbl001", Caption = "ラベル", BindPath = "labelPath" } };
            var xaml = target.CreateXaml(TestHelper.CreateTestParent())[1];

            var actual = TestHelper.GetFrameworkElement<Label>(xaml);
            Assert.AreEqual("lbl001", actual.Name);
            var tb = (TextBlock)actual.Content;
            Assert.AreEqual("labelPath", tb.GetBindingExpression(TextBlock.TextProperty).ParentBinding.Path.Path);
            Assert.AreEqual(BindingMode.OneWay, tb.GetBindingExpression(TextBlock.TextProperty).ParentBinding.Mode);

        }

        [TestMethod()]
        public void フォーマット指定なLabelのXAML生成()
        {
            var target = new LabelViewControl { Item = new ViewLayoutItem { Name = "lbl001", Caption = "ラベル", BindPath = "labelPath" } };
            target.StringFormat = "yyyy/mm/dd";
            var xaml = target.CreateXaml(TestHelper.CreateTestParent())[1];

            var actual = TestHelper.GetFrameworkElement<Label>(xaml);
            Assert.AreEqual("lbl001", actual.Name);
            var tb = (TextBlock)actual.Content;
            Assert.AreEqual("labelPath", tb.GetBindingExpression(TextBlock.TextProperty).ParentBinding.Path.Path);
            Assert.AreEqual("yyyy/mm/dd", tb.GetBindingExpression(TextBlock.TextProperty).ParentBinding.StringFormat);
            Assert.AreEqual(BindingMode.OneWay, tb.GetBindingExpression(TextBlock.TextProperty).ParentBinding.Mode);
        }

        [TestMethod()]
        public void LabelViewControlの編集画面が表示可能()
        {
            var target = new LabelViewControl { Item = new ViewLayoutItem { Name = "lbl001", Caption = "ラベル", BindPath = "labelPath" } };
            var baml = ViewUtil.BuildContent(target);
            Assert.IsNotNull(baml);
        }

    }
}
